package com.marquee;


import java.util.ArrayList;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class Dialog_Notification extends DialogFragment {

	View view;
	
/*	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder mBuilder = new AlertDialog.Builder(
				getActivity());
		LayoutInflater mLayoutInflater = getActivity().getLayoutInflater();
		mBuilder.setView(mLayoutInflater
				.inflate(R.layout.dialog_main, null));
		mBuilder.setTitle("Dialog Titleeeeee");
		mBuilder.setMessage("Dialog Messageeeeeee");
		return mBuilder.create();
	}*/
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    	view = (RelativeLayout) inflater.inflate(R.layout.notification_fragment, container, false);
    	getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    	
    	ImageButton IB_close = (ImageButton)view.findViewById(R.id.IB_close);
    	IB_close.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				getDialog().dismiss();
				
			}
		});
    	
    	//listview, arraylist, adapter 초기화
    	ListView lstActionList = (ListView)view.findViewById(R.id.listview_notification);
    	ArrayList<Notification> arrPersonList = new ArrayList<Notification>();
    	AddListViewAdapter adptActionList = new AddListViewAdapter(getActivity().getApplicationContext(), R.layout.notification_list_item, arrPersonList);

    	//adapter 세팅
    	lstActionList.setAdapter(adptActionList);

    	//list의 내용을 채울 ArrayList 작성

    	Resources res = this.getResources();
    	Notification mNotification;
    	
    	mNotification = new Notification();
    	mNotification.setProfile(res.getDrawable(R.drawable.no_avatar));
    	mNotification.setTitle("박상권님에게서 친구요청이 왔습니다.");
    	mNotification.setTime("2월 27일 03:02");
    	arrPersonList.add(mNotification);
    	
    	mNotification = new Notification();
    	mNotification.setProfile(res.getDrawable(R.drawable.no_avatar));
    	mNotification.setTitle("김철수님에게서 친구요청이 왔습니다.");
    	mNotification.setTime("2월 27일 01:15");
    	arrPersonList.add(mNotification);
    	
    	mNotification = new Notification();
    	mNotification.setProfile(res.getDrawable(R.drawable.no_avatar));
    	mNotification.setTitle("3월 3일의 미팅이 성사되었습니다.");
    	mNotification.setTime("2월 26일 15:26");
    	arrPersonList.add(mNotification);
    	

    	
    	
    	//listview refresh(?)
    	adptActionList.notifyDataSetChanged();
    	
    	
    	
    	
    	
    	
    	
    	
    	
        return view;
    }
    

	public class Notification {

		 private Drawable profile;
		 private Drawable type;
		 private String title;
		 private String time;
		 
		 public Drawable getProfile() {
		  return profile;
		 }
		 public void setProfile(Drawable icon) {
		  this.profile = icon;
		 }
		 
		 public Drawable getType() {
			  return type;
			 }
			 public void setType(Drawable type) {
			  this.type = type;
			 }
		 
		 public String getTitle() {
		  return title;
		 }
		 public void setTitle(String title) {
		  this.title = title;
		 }
		 public String getTime() {
			  return time;
			 }
			 public void setTime(String time) {
			  this.time = time;
			 }
		}
	
	class AddListViewAdapter extends ArrayAdapter<Notification>{
		 private Context context;
		 private int layout;
		 private ArrayList<Notification> personList;
		 private LayoutInflater layoutInflater;
		 
		 
		 public AddListViewAdapter(Context context, int textViewResourceId, ArrayList<Notification> objects) {
		  super(context, textViewResourceId, objects);
		  // TODO Auto-generated constructor stub
		  this.context = context;
		  this.layout = textViewResourceId;
		  this.personList = objects;
		                //LayoutInflater 생성
		  this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		 }
		 
		 @Override
		 public View getView(int position, View convertView, ViewGroup parent) {
		  // TODO Auto-generated method stub
			 Notification mPerson = personList.get(position);

		  if(convertView == null){
		                        //xml 파일로 정의된 layout 을 View 클래스로 변환
		   convertView = layoutInflater.inflate(layout, null);
		  }

		  if(mPerson != null){
		                        //convertView 라는 View 오브젝트를 이용해서 각각의 콤포넌트를 컨트롤
			  ImageView imgProfile = (ImageView) convertView.findViewById(R.id.notification_profile_img);
			  ImageView imgType = (ImageView) convertView.findViewById(R.id.notification_type_img);
		   TextView tvTitle = (TextView) convertView.findViewById(R.id.notification_title);
		   TextView tvTime = (TextView) convertView.findViewById(R.id.notification_time);
		   
		   imgProfile.setImageDrawable(mPerson.getProfile());
		   imgType.setImageDrawable(mPerson.getType());
		   tvTitle.setText(mPerson.getTitle());
		   tvTime.setText(mPerson.getTime());
		  
		  }

		  return convertView;
		 }
		}
	
}

